home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mdl4viewslayout.py < prev    next >
Text File  |  2004-01-05  |  8KB  |  297 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Plug-in which define the 4-views screen layouts.
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/mdl4viewslayout.py,v 1.2 2000/06/03 10:25:30 alexander Exp $
  12.  
  13.  
  14. Info = {
  15.    "plug-in":       "Model 4-Views Layout",
  16.    "desc":          "Model 4-views Screen Layouts.",
  17.    "date":          "13 dec 98",
  18.    "author":        "Armin Rigo",
  19.    "author e-mail": "arigo@planetquake.com",
  20.    "quark":         "Version 5.3" }
  21.  
  22.  
  23. import quarkpy.qhandles   
  24. from quarkpy.mdlmgr import *
  25.  
  26.  
  27. #
  28. # See comments in map4viewslayout.py.
  29. #
  30.  
  31. class FourViewsLayout(ModelLayout):
  32.     "The 4-views layout, abstract class for FourViewsLayout1 and FourViewsLayout2."
  33.  
  34.     def buildbase(self, form):
  35.  
  36.         #
  37.         # We put the standard left panel first.
  38.         #
  39.  
  40.         self.rotateviews = []   # dissociate self.rotateviews and self.views
  41.         self.bs_leftpanel(form)
  42.  
  43.         #
  44.         # Create the four views.
  45.         #
  46.  
  47.         self.ViewXY = form.mainpanel.newmapview()
  48.         self.ViewXZ = form.mainpanel.newmapview()
  49.         self.ViewYZ = form.mainpanel.newmapview()
  50.         self.View3D = form.mainpanel.newmapview()
  51.  
  52.         #
  53.         # Put these 4 views in the view lists.
  54.         #
  55.  
  56.         self.views[:] = [self.ViewXY, self.ViewXZ, self.ViewYZ, self.View3D]
  57.         self.baseviews = self.views[:]
  58.         self.rotateviews[:] = [self.ViewXY, self.ViewXZ, self.ViewYZ]
  59.  
  60.         #
  61.         # Setup initial display parameters.
  62.         #
  63.  
  64.         scale = 2.0   # default value
  65.  
  66.         self.ViewXY.info = {
  67.           "type": "XY",     # XY view
  68.           "angle": 0.0,     # compass angle
  69.           "scale": scale,   # scale
  70.           "vangle": 0.0}    # vertical angle
  71.  
  72.         self.ViewXZ.info = {
  73.           "type": "XZ",     # XZ view
  74.           "angle": 0.0,
  75.           "scale": scale,
  76.           "vangle": 0.0}
  77.  
  78.         self.ViewYZ.info = {
  79.           "type": "YZ",     # YZ view
  80.           "angle": 0.0,
  81.           "scale": scale,
  82.           "vangle": 0.0}
  83.  
  84.         quarkpy.qhandles.flat3Dview(self.View3D, self)
  85.         del self.View3D.info["noclick"] 
  86.  
  87.  
  88.     #
  89.     # The following function is called when the configuration changed.
  90.     # We show or hide the red lines here.
  91.     #
  92.  
  93.     def setupchanged(self, level):
  94.  
  95.         #
  96.         # First call the inherited "setupchanged".
  97.         #
  98.  
  99.         ModelLayout.setupchanged(self, level)
  100.  
  101.  
  102.         #
  103.         # Read the old flags and set both red lines by default.
  104.         #
  105.  
  106.         flagsXY = self.ViewXY.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  107.         flagsXZ = self.ViewXZ.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  108.  
  109.         #
  110.         # Remove the 2nd red line if required.
  111.         #
  112.  
  113.         if not MapOption("RedLines2"):
  114.             flagsXY = flagsXY &~ MV_TOPREDLINE
  115.             flagsXZ = flagsXZ &~ MV_BOTTOMREDLINE
  116.  
  117.         #
  118.         # Update the flags.
  119.         #
  120.  
  121.         self.ViewXY.flags = flagsXY
  122.         self.ViewXZ.flags = flagsXZ
  123.  
  124.     #
  125.     # The following function is called to compute the limits of
  126.     # the visible (non-grayed-out) areas for each map view.
  127.     #
  128.  
  129.     def setupdepth(self, view):
  130.  
  131.         #
  132.         # First check the "view" parameter.
  133.         #
  134.  
  135.         if not (view in (self.ViewXY, self.ViewXZ, self.ViewYZ)):
  136.             return
  137.  
  138.         #
  139.         # To compute the visible areas for the XY view, we
  140.         # get the rectangular area (in pixels) of the XZ view.
  141.         #
  142.  
  143.         x1,y1,x2,y2 = self.ViewXZ.redlinesrect
  144.  
  145.         #
  146.         # The line below does this :
  147.         #  * take a corner of the above rectangle
  148.         #  * compute the 3D coordinates of any point above this corner
  149.         # This gives a 3D point that is at the top limit of the visible area for the XY view.
  150.         #  * project this 3D point on the XY view
  151.         #  * keep only the z coordinate (i.e. the depth) of this projection
  152.         # This gives the depth of the top limit, which is what we wanted.
  153.         #
  154.         # The second line does the same for the other corner, which gives
  155.         # the bottom limit of the visible area.
  156.         #
  157.  
  158.         xydepth = (self.ViewXY.proj(self.ViewXZ.space(x1, y1, 0.0)).z,
  159.                    self.ViewXY.proj(self.ViewXZ.space(x2, y2, 0.0)).z)
  160.  
  161.         #
  162.         # Do it again for the XZ view...
  163.         #
  164.  
  165.         x1,y1,x2,y2 = self.ViewXY.redlinesrect
  166.         corner1 = self.ViewXY.space(x1, y1, 0.0)
  167.         corner2 = self.ViewXY.space(x2, y2, 0.0)
  168.         
  169.         xzdepth = (self.ViewXZ.proj(corner2).z,
  170.                    self.ViewXZ.proj(corner1).z)
  171.  
  172.         #
  173.         # Do it again for the YZ view...
  174.         #
  175.  
  176.         yzdepth = (self.ViewYZ.proj(corner1).z,
  177.                    self.ViewYZ.proj(corner2).z)
  178.  
  179.         #
  180.         # Depending on the draw mode, items may or may not be grayed
  181.         # out. If they are, we must redraw a view when the other one
  182.         # is scrolled, in case objects came in or out of view. This
  183.         # is done by calling "setdepth". Otherwise, we directly set
  184.         # the map view's "depth" attribute, which doesn't redraw the
  185.         # view.
  186.         #
  187.  
  188.         redraw = self.editor.drawmode & DM_MASKOOV
  189.  
  190.         if redraw and (view is not self.ViewXY):
  191.             self.ViewXY.setdepth(xydepth)
  192.         else:
  193.             self.ViewXY.depth = xydepth
  194.  
  195.         if redraw and (view is not self.ViewXZ):
  196.             self.ViewXZ.setdepth(xzdepth)
  197.         else:
  198.             self.ViewXZ.depth = xzdepth
  199.  
  200.         if redraw and (view is not self.ViewYZ):
  201.             self.ViewYZ.setdepth(yzdepth)
  202.         else:
  203.             self.ViewYZ.depth = yzdepth
  204.  
  205.  
  206.     #
  207.     # Functions to read and store the layout (window positions,...)
  208.     # in the Setup.
  209.     #
  210.  
  211.     def readconfig(self, config):
  212.         ModelLayout.readconfig(self, config)
  213.         secs = config["secs"]
  214.         if type(secs)==type(()) and len(secs)==2:
  215.             self.editor.form.mainpanel.sections = (secs[:1], secs[1:])
  216.  
  217.     def writeconfig(self, config):
  218.         ModelLayout.writeconfig(self, config)
  219.         hsec, vsec = self.editor.form.mainpanel.sections
  220.         config["secs"] = hsec[0], vsec[0]
  221.  
  222.  
  223.  
  224.  
  225. class FourViewsLayout2(FourViewsLayout):
  226.  
  227.     shortname = "4 views"
  228.  
  229.     def buildscreen(self, form):
  230.  
  231.         #
  232.         # Build the base.
  233.         #
  234.  
  235.         self.buildbase(form)
  236.  
  237.         #
  238.         # Divide the main panel into 4 sections.
  239.         # horizontally, 2 sections split at 50% of the width
  240.         # vertically, 2 sections split at 50% of the height
  241.         #
  242.  
  243.         form.mainpanel.sections = ((0.50, ), (0.50,))
  244.  
  245.         #
  246.         # Put the XY view in the section (1,0)
  247.         #
  248.  
  249.         self.ViewXY.section = (1,0)
  250.  
  251.         #
  252.         # Put the XZ view in the section (1,1).
  253.         #
  254.  
  255.         self.ViewXZ.section = (1,1)
  256.  
  257.         #
  258.         # Put the YZ view in the section (0,1).
  259.         #
  260.  
  261.         self.ViewYZ.section = (0,1)
  262.  
  263.         #
  264.         # The 3D view is in the section (0,0) (it is there by default).
  265.         #
  266.  
  267.         #
  268.         # Link the horizontal position of the XZ view to that of the
  269.         # XY view, and the vertical position of the XZ and YZ views,
  270.         # and remove the extra scroll bars.
  271.         #
  272.  
  273.         self.sblinks.append((0, self.ViewXZ, 0, self.ViewXY))
  274.         self.sblinks.append((1, self.ViewXZ, 1, self.ViewYZ))
  275.         self.sblinks.append((1, self.ViewXY, 0, self.ViewYZ))
  276.         self.ViewYZ.flags = self.ViewYZ.flags &~ (MV_HSCROLLBAR | MV_VSCROLLBAR)
  277.         self.ViewXY.flags = self.ViewXY.flags &~ MV_HSCROLLBAR
  278.  
  279.  
  280.  
  281.  
  282. #
  283. # Register the new layout. (this one is the default one, so add it at the front of the list)
  284. #
  285.  
  286. LayoutsList.insert(0, FourViewsLayout2)
  287.  
  288. # ----------- REVISION HISTORY ------------
  289. #
  290. #
  291. # $Log: mdl4viewslayout.py,v $
  292. # Revision 1.2  2000/06/03 10:25:30  alexander
  293. # added cvs headers
  294. #
  295. #
  296. #
  297. #